package com.example.demo.controller;

import com.example.demo.Service.WxPayService;
import com.example.demo.utils.model.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;


/**
 * @author xueyj
 * @date 2020/12/20
 */
@RestController
@Slf4j
@RequestMapping("/wx/wxPay")
public class SWxPayController {

    @Autowired
    private WxPayService wxPayService;

    /**
     * 统一下单v3版本
     */
    @RequestMapping(value = "/unifiedOrder/{openId}/{produceCode}", method = RequestMethod.GET)
    public CommonResult unifiedOrder(@PathVariable("openId") String openId,
                                     @PathVariable("produceCode") Integer produceCode) throws IOException, NoSuchAlgorithmException, InvalidKeyException, SignatureException {
        return wxPayService.unfiedOrder(openId, produceCode);
    }

    @RequestMapping(value = "/notifyWeiXinPayV3", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult notifyWeiXinPayV3(HttpServletRequest request) throws IOException, GeneralSecurityException {
        log.info("微信回调接口进入");
        return wxPayService.notifyWeiXinPayV3(request);
    }
}




